//
//  HomeMainView.m
//  DirectProDuct
//
//  Created by hl on 16/1/20.
//  Copyright (c) 2016年 ping. All rights reserved.
//

#import "HomeMainView.h"

@implementation HomeMainView
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createdSubVuew1];
    }
    return self;
}
-(void)createdSubVuew1{
    NSArray *titleArr = @[@"系统首页",@"站内信件",@"系统公告",@"资金明细",@"会员管理",@"业务管理",@"财务管理",@"账户设置"];
    for (int i = 0; i < 8; i++) {
        UIButton *btn = [self setImage:[UIImage imageNamed:@"240.jpg"] withTitle:[titleArr objectAtIndex:i] withBackColor:[UIColor grayColor] withIndex:i forState:UIControlStateNormal];
        [btn addTarget:self.delegate action:@selector(buttonCilicked:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        
        if (i == 7) {
            [self createdSubView2WithFrame:btn.bottom];
        }
    }
}
- (UIButton *)setImage:(UIImage *)image withTitle:(NSString *)title withBackColor:(UIColor *)backColor withIndex:(int)index forState:(UIControlState)stateType {
    
    //UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
    int row = index%4;
    int hang = index/4;
    int X = (KScreenWidth - 60 * _kscW * 4 - 13 * _kscW *3)/2;
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(X + (60+13 )* _kscW * row, 17 * _kscH + (60 + 18)*_kscH * hang, 60 * _kscW, 60 * _kscH)];
    btn.tag = index;
    btn.layer.cornerRadius = 4;
    btn.clipsToBounds = YES;
    btn.backgroundColor = backColor;
    [btn setImage:image forState:UIControlStateNormal];
    CGSize titleSize = [title sizeWithFont:[UIFont fontWithName:TextJiaCu size:13.0f]];
    
    [btn.imageView setContentMode:UIViewContentModeCenter];
    
    [btn setImageEdgeInsets:UIEdgeInsetsMake(-8.0,0.0,0.0,-titleSize.width)];
    
    [btn setImage:image forState:stateType];
    
    
    
    [btn.titleLabel setContentMode:UIViewContentModeCenter];
    
    [btn.titleLabel setBackgroundColor:[UIColor clearColor]];
    
    [btn.titleLabel setFont:[UIFont fontWithName:TextJiaCu size:13.0f]];
    
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(45 * _kscH,-image.size.width,0.0,0.0)];
    
    [btn setTitle:title forState:stateType];
    return btn;
    
}
-(void)createdSubView2WithFrame:(float)BtnBottom{
    UIView *tishiView = [[UIView alloc] initWithFrame:CGRectMake(0, BtnBottom + 17 * _kscH, KScreenWidth, 46 * _kscH)];
    tishiView.backgroundColor = RGBACOLOR(255, 210, 219, 1);
    [self addSubview:tishiView];
    
    UILabel *lineLab1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 11 * _kscH, 110 * _kscW, 1 * _kscH)];
    lineLab1.backgroundColor = [UIColor redColor];
    [tishiView addSubview:lineLab1];
    
    UILabel *tipLab = [[UILabel alloc] initWithFrame:CGRectMake(lineLab1.right+4 * _kscW, 2 * _kscH, 87 * _kscW, 18 * _kscH)];
    tipLab.textColor = [UIColor whiteColor];
    tipLab.text = @"收入数据";
    tipLab.backgroundColor = [UIColor redColor];
    tipLab.textAlignment = NSTextAlignmentCenter;
    tipLab.layer.cornerRadius = 8;
    tipLab.clipsToBounds = YES;
    tipLab.font = [UIFont fontWithName:TextJiaCu size:12.0f];
    [tishiView addSubview:tipLab];
    
    UILabel *lineLab2= [[UILabel alloc] initWithFrame:CGRectMake(tipLab.right + 4 * _kscW, lineLab1.top, KScreenWidth - tipLab.right - 4 * _kscW, 1 * _kscH)];
    lineLab2.backgroundColor = [UIColor redColor];
    [tishiView addSubview:lineLab2];
    
    self.searchField = [[UITextField alloc] initWithFrame:CGRectMake(25 * _kscW, tipLab.bottom + 2*_kscH, KScreenWidth - 50 * _kscW, 20 * _kscH)];
    self.searchField.placeholder = @"请输入日期,查询收入明细";
    self.searchField.layer.cornerRadius = 8;
    self.searchField.clipsToBounds = YES;
    self.searchField.backgroundColor = [UIColor whiteColor];
    self.searchField.returnKeyType = UIReturnKeySearch;
    self.searchField.font = [UIFont systemFontOfSize:12.0];
    [tishiView addSubview:self.searchField];
    
    UIView *searchBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30 * _kscH, self.searchField.height)];
    self.searchField.leftView = searchBackView;
    self.searchField.leftViewMode = UITextFieldViewModeAlways;
    
    self.searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(5 *_kscW, 0, 20 * _kscW, 20 * _kscH)];
    self.searchBtn.tag = 8;
    [self.searchBtn setBackgroundColor:[UIColor blackColor]];
    [self.searchBtn addTarget:self.delegate action:@selector(buttonCilicked:) forControlEvents:UIControlEventTouchUpInside];
    [searchBackView addSubview:self.searchBtn];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
